/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.helper_classes;

import cse308.GUIUtilityClass;
import cse308.General;
import cse308.GeneralEntity;
import cse308.entities.Minute;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.http.Part;

/**
 *
 * @author Enyu
 */
public class MinuteClass implements GeneralTest {

    private String identifier;
    private String date;
    private String grp;
    private File minute;
    private byte[] minutes;
    private Part minutesPart;

    public MinuteClass(Minute entity) {
        this.identifier = entity.getIdentifier();
        this.date = entity.getDate();
        this.grp = entity.getGrp();
        try {
            byte[] byteArray=entity.getMinutes();
            this.minute = GUIUtilityClass.convertToFile(byteArray, "minutes" + GUIUtilityClass.minuteIterator + ".txt");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MinuteClass.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MinuteClass.class.getName()).log(Level.SEVERE, null, ex);
        }
        GUIUtilityClass.minuteIterator++;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    
    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getGrp() {
        return grp;
    }

    public void setGrp(String group) {
        this.grp = group;
    }

  

    @Override
    public String getIdentifier2() {
        return this.grp;
    }


    @Override
    public ArrayList<Map<String, General>> getMap() {
        ArrayList<Map<String, General>> k = new ArrayList();
        return k;
    }

    @Override
    public ArrayList<List<String>> getList() {
        ArrayList<List<String>> empty = new ArrayList<List<String>>();
        return empty;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("CSE_308_ABETPU");
        EntityManager em = emf.createEntityManager();
        return em.find(Minute.class, this.identifier);
    }

    @Override
    public boolean equalsEntity(GeneralEntity toEqual) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

   // @Override
    public void updateRelationship(GeneralEntity ge1) {
        return;
    }

   public Part getMinutesPart() {
        return minutesPart;
    }

    public void setMinutesPart(Part minutesPart) {
        this.minutesPart = minutesPart;
        this.minutes = GUIUtilityClass.convertToBytesByPart(minutesPart);
    }


    public File getMinute() {
        return minute;
    }

    public void setMinute(File minute) {
        this.minute = minute;
    }

    public byte[] getMinutes() {
        return minutes;
    }

    public void setMinutes(byte[] minutes) {
        this.minutes = minutes;
    }
}
